package tmhprediction.main;

import tmhprediction.classification.TMHClassifier;

/***
 * calculates result by merging result from svm1 and svm2
 * sets all predictions in svm2 to zero for proteins that are decided to be not TM by svm1
 * 
 * @author steckl
 *
 */
public class TMHMergeSVMs {
	
	private TMHResultMap finalResult;
	
	public TMHMergeSVMs(TMHResultMap svm1res, TMHResultMap svm2res) throws Exception {
		
		// didn't know if we need a copy or if i just overwrite svm2res
		finalResult = (TMHResultMap) svm2res.clone();
		
		int nameLength;
		String name;
		for(String sProtein_pos : svm2res.keySet())
		{
			nameLength = sProtein_pos.lastIndexOf("_");
			name = sProtein_pos.substring(0,nameLength);
			
			if(svm1res.containsKey(name)) {
				// set result to non-TMH if svm1 predicted this protein to be non-tranmembran overall
				if(svm1res.getPredicted(name) == TMHClassifier.PARSEDSYMBOLNONTMHRESIDUE) {
					finalResult.setPredicted(sProtein_pos,TMHClassifier.PARSEDSYMBOLNONTMHRESIDUE);
				}
				
			} else { // shouldn't happen in real application, but happens for our evaluation data
				// do nothing
			}
		
		}
	}
	
	public TMHResultMap getFinalDecision() {
		return finalResult;
	}
}
